package com.example.demo.controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class loginController {
    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session) {
        //校验参数
        if (!StringUtils.hasLength(userName) || !StringUtils.hasLength(password))
            return false;
        //本来应该是去数据库里面查数据校验一下是否正确现在不用了
        if ("zyh".equals(userName) && "zyh".equals(password)) {
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }
    @RequestMapping("/getLoginUser")
    public String getLoginUser(HttpSession session){
        return (String) session.getAttribute("userName");
    }
}
